package com.wxzz.elearing.evaluation.api.app;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.evaluation.dto.*;
import com.wxzz.elearing.evaluation.entity.BusinessCategoryRule;
import com.wxzz.elearing.evaluation.entity.BusinessCategoryRuleGroupStatisticsData;
import com.wxzz.elearing.evaluation.entity.BusinessCategoryRuleHistory;
import com.wxzz.elearing.evaluation.entity.Topic;
import com.wxzz.elearing.evaluation.service.IBusinessCategoryRuleService;
import com.wxzz.elearing.evaluation.service.ITopicService;
import com.wxzz.elearing.evaluation.vo.CredentialListVo;
import com.wxzz.elearing.evaluation.vo.TopicVo;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工厂体检/星级认证 前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-10
 */
@RestController
@RequestMapping("/wx-business-category-rule")
@Api(tags = "工厂体检/星级认证接口(小程序)")
public class WxBusinessCategoryRuleController {

    @Autowired
    private IBusinessCategoryRuleService businessCategoryRuleService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "查询星级认证项目(小程序)", notes = "查询星级认证项目(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listBusinessCategoryRuleByCategory", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategoryRule>>> listBusinessCategoryRuleByCategory(@RequestHeader String token, @RequestBody WxBusinessCategoryRuleDto wxBusinessCategoryRuleDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return businessCategoryRuleService.listBusinessCategoryRuleByCategory(jsonObject.getLong("id"), wxBusinessCategoryRuleDto);
    }

    @ApiOperation(value = "列出个人工厂体检/星级认证记录(小程序)", notes = "列出个人工厂体检/星级认证记录(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listBusinessCategoryRuleHistory", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategoryRuleHistory>>> listBusinessCategoryRuleHistory(@RequestHeader String token, @Valid @RequestBody BusinessCategoryRuleHistoryDto businessCategoryRuleHistoryDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        businessCategoryRuleHistoryDto.setWxUserId(jsonObject.getLong("id"));
        return businessCategoryRuleService.listBusinessCategoryRuleHistory(businessCategoryRuleHistoryDto);
    }

    @ApiOperation(value = "列出企业工厂体检/星级认证记录(小程序)", notes = "列出企业工厂体检/星级认证记录(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listBusinessCategoryRuleHistory4enterprise", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategoryRuleHistory>>> listBusinessCategoryRuleHistory4enterprise(@RequestHeader String token, @Valid @RequestBody BusinessCategoryRuleHistoryDto businessCategoryRuleHistoryDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        businessCategoryRuleHistoryDto.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        return businessCategoryRuleService.listBusinessCategoryRuleHistory(businessCategoryRuleHistoryDto);
    }

    @ApiOperation(value = "查询星级认证详情(小程序)", notes = "查询星级认证详情(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectBusinessCategoryRuleById/{businessCategoryRuleById}", method = RequestMethod.POST)
    public ReturnVO<BusinessCategoryRule> selectBusinessCategoryRuleById(@RequestHeader String token,@PathVariable Long businessCategoryRuleById) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return businessCategoryRuleService.selectBusinessCategoryRuleById(jsonObject,businessCategoryRuleById);
    }

    @ApiOperation(value = "查询星级认证证书(小程序)", notes = " 查询星级认证证书(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectCredentialListVo", method = RequestMethod.POST)
    public ReturnVO<CredentialListVo> selectCredentialListVo(@RequestHeader String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return businessCategoryRuleService.selectCredentialListVo(jsonObject);
    }

    @ApiOperation(value = "查询该企业的班组英雄榜(小程序)", notes = " 查询该企业的班组英雄榜(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectBusinessCategoryRuleGroupStatisticsDataByGroup", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategoryRuleGroupStatisticsData>>>  selectBusinessCategoryRuleGroupStatisticsDataByGroup(HttpServletResponse response, @RequestHeader String token, @RequestBody BusinessCategoryRuleGroupStatisticsDataByGroupDto businessCategoryRuleGroupStatisticsDataByGroupDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return businessCategoryRuleService.selectBusinessCategoryRuleGroupStatisticsDataByGroup(response,jsonObject.getLong("enterpriseId"),businessCategoryRuleGroupStatisticsDataByGroupDto);
    }
}
